home *** CD-ROM | disk | FTP | other *** search
- #include "gGlobals.h"
-
- #include <pascal.h>
- #include <Scrap.h>
- #include <Desk.h>
- #include <string.h>
- #include <stdio.h>
- #include <Fonts.h>
- #include <Math.h>
-
- /*********************************************
-
- Allow the user to set the compression parameters with the standard compression dialog.
-
- *********************************************/
-
- void InitSetCompression()
- {
- gStandardP.flags = scShowMotionSettings;
- gStandardP.theCodecType = kCodecType;
- gStandardP.theCodec = kCodecID;
- gStandardP.spatialQuality = kCodecQuality;
- gStandardP.temporalQuality = 0;
- gStandardP.depth = kCodecDepth;
- gStandardP.frameRate = kFrameRate<<16;
- gStandardP.keyFrameRate = kFrameRate;
- } /* End of () */
-
- /*********************************************
-
- Allow the user to set the compression parameters with the standard compression dialog.
-
- *********************************************/
-
- SetCompression()
- { ComponentInstance ci;
- Point where;
-
- where.h = where.v = -2;
- ci = OpenDefaultComponent(StandardCompressionType,0);
- if ( ci == nil ) {
- Error("Couldn't open StdCompression",0); return;
- }
-
- SCGetCompression(ci,&gStandardP,where);
-
- } /* End of () */
-
- /*
-
- Allow the user to set the number of stages she wants the processing to take.
- */
- SetStages()
- {
- #define STAGE_DLOG 128
- #define IT_STAGES 3
- #define IT_LINEAR 4
- #define IT_OK 1
- #define IT_CANCEL 2
-
- CGrafPtr savePort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit,lastItem = -1;
- Boolean done = false;
- Point tp;
- GDHandle saveGD;
- Str255 text;
- long num;
- long stageCount = gNumberSteps;
- Boolean linear = true;
-
- if ((theDialog = GetNewDialog(STAGE_DLOG, nil, (WindowPtr) -1)) == nil )
- return;
-
- GetMouse(&tp);
- GetGWorld(&savePort,&saveGD);
- SetPort(theDialog);
- GetDItem(theDialog,IT_OK,&itemType,&itemHdl,&itemRect);
- PenSize(3,3);
- InsetRect(&itemRect,-4,-4);
- FrameRoundRect(&itemRect,16,16);
-
-
- GetDItem(theDialog,IT_STAGES,&itemType,&itemHdl,&itemRect);
- NumToString(stageCount, text);
- SetIText(itemHdl,text);
-
- SelIText(theDialog,IT_STAGES,0,32767);
-
- GetDItem(theDialog,IT_LINEAR,&itemType,&itemHdl,&itemRect);
- SetCtlValue((ControlHandle)itemHdl,linear);
- HiliteControl((ControlHandle)itemHdl,255);
-
- while ( !done ) {
- ModalDialog(nil, &itemHit);
- if ( itemHit != lastItem ) {
- switch( lastItem ) {
- case IT_STAGES :
- GetDItem(theDialog,IT_STAGES,&itemType,&itemHdl,&itemRect);
- GetIText(itemHdl,text);
- StringToNum(text, &num);
- if ( num > 0 ) stageCount = num;
- else { SysBeep(1);
- NumToString(stageCount, text);
- SetIText(itemHdl,text);
- if (itemHit == IT_OK) itemHit = -1;
- }
- break;
- }
- lastItem = itemHit;
- }
-
- switch ( itemHit ) {
- case IT_OK :
- gNumberSteps = stageCount;
- done = true;
- break;
- case IT_CANCEL : done = true;
- break;
- case IT_LINEAR:
- linear = !linear;
- GetDItem(theDialog,IT_LINEAR,&itemType,&itemHdl,&itemRect);
- SetCtlValue((ControlHandle)itemHdl,linear);
- break;
- }
- }
- CloseDialog(theDialog);
- SetGWorld(savePort,saveGD);
- } /* End of () */
-
-
- /********************************************
-
- Allocate the image buffers for the processing
-
- ********************************************/
-
- OSErr AllocateBuffers()
- {
-
- Rect rect = gRect;
- OSErr result = 0;
- short depth = gDepth > 32 ? (gDepth-32) : gDepth;
- CTabHandle clut = nil;
-
- OffsetRect(&rect,-rect.left,-rect.top);
-
- if ( gDepth > 32 )
- clut = GetCTable(gDepth);
-
- if ( gDstWorld ) {
- DisposeGWorld(gDstWorld);
- gDstWorld = nil;
- }
- if ( gBufferWorld ) {
- DisposeGWorld(gBufferWorld);
- gBufferWorld = nil;
- }
- if ( (result=NewGWorld(&gWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
- if ( (result=NewGWorld(&gAltWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gAltWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
- if ( (result=NewGWorld(&gBufferWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gBufferWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
- if ( (result=NewGWorld(&gDstWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gDstWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
- done:
- if ( result ) {
- if ( gWorld ) DisposeGWorld(gWorld);
- gWorld= nil;
- if ( gAltWorld ) DisposeGWorld(gAltWorld);
- gAltWorld= nil;
- if ( gDstWorld ) DisposeGWorld(gDstWorld);
- gDstWorld= nil;
- if ( gBufferWorld ) DisposeGWorld(gBufferWorld);
- gBufferWorld= nil;
- }
- if ( clut ) DisposeCTable(clut);
- return(result);
- } /* End of () */
-
-
- /*********************************************
-
- Show a preview of some stage in the process.
-
- ********************************************/
- DoPreview()
- {
- #define PV_DLOG 129
- #define IT_STAGE 4
- #define IT_OK 1
- #define IT_CANCEL 2
-
- CGrafPtr savePort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit,lastItem = -1;
- Boolean done = false;
- Point tp;
- GDHandle saveGD;
- Str255 text;
- long num;
- long whichStage = gNumberSteps/2;
-
-
- if ((theDialog = GetNewDialog(PV_DLOG, nil, (WindowPtr) -1)) == nil )
- return;
-
- GetMouse(&tp);
- GetGWorld(&savePort,&saveGD);
- SetPort(theDialog);
- GetDItem(theDialog,IT_OK,&itemType,&itemHdl,&itemRect);
- PenSize(3,3);
- InsetRect(&itemRect,-4,-4);
- FrameRoundRect(&itemRect,16,16);
-
-
- GetDItem(theDialog,IT_STAGE,&itemType,&itemHdl,&itemRect);
- NumToString(whichStage, text);
- SetIText(itemHdl,text);
-
- SelIText(theDialog,IT_STAGE,0,32767);
-
- while ( !done ) {
- ModalDialog(nil, &itemHit);
-
- if ( itemHit != lastItem ) { /* Check number, if user goes to another control */
- switch( lastItem ) {
- case IT_STAGE :
- GetDItem(theDialog,IT_STAGE,&itemType,&itemHdl,&itemRect);
- GetIText(itemHdl,text);
- StringToNum(text, &num);
- if ( num > 0 && num <= gNumberSteps )
- whichStage = num;
- else {
- SysBeep(1);
- NumToString(whichStage,text);
- SetIText(itemHdl,text);
- if (itemHit == IT_OK) itemHit = -1;
- }
- break;
- }
- lastItem = itemHit;
- }
-
- switch ( itemHit ) {
- case IT_OK : done = true;
- break;
- case IT_CANCEL : whichStage = 0;
- done = true;
- break;
- }
- }
- CloseDialog(theDialog);
-
- if ( whichStage ) {
- Str15 numStr;
- Rect rect;
-
- BlockMove("\pPreview ",text,10);
- NumToString(whichStage, numStr);
- BlockMove(&numStr[1],&text[text[0]+1],(Size)numStr[0]);
- text[0] = text[0] + numStr[0];
-
- rect = gSrcWindow->portRect;
- SetGWorld(gSrcWindow,nil);
- LocalToGlobal((Point *)&rect.top);
- LocalToGlobal((Point *)&rect.bottom);
- OffsetRect(&rect,20,20);
- if ( gOversample ) {
- rect.right = rect.left + (rect.right-rect.left)/2;
- rect.bottom = rect.top + (rect.bottom-rect.top)/2;
- }
- SetGWorld(savePort,saveGD);
- if ( gDstWindow ) {
- CloseWindow((WindowPtr)gDstWindow);
- gDstWindow = nil;
- }
- if ( (gDstWindow = (CWindowPtr)NewCWindow(nil,&rect,text,true,
- zoomDocProc,(WindowPtr)-1,true,0)) == nil ) {
- Error("NewCWindow Failed",0);
- goto done;
- }
- BringToFront((WindowPtr)gDstWindow);
- HiliteWindow((WindowPtr)gDstWindow,true);
- SetGWorld((CGrafPtr)gDstWorld,nil);
- PaintRect(&gDstWorld->portRect);
-
-
- if ( gDstWorld && gWorld && gAltWorld )
- DoStage(whichStage,gNumberSteps,gBackwards);
-
- SetGWorld((CGrafPtr)gDstWindow,nil);
- CopyBits((BitMap *)*gDstWorld->portPixMap,(BitMap *)*gDstWindow->portPixMap,
- &gDstWorld->portRect,&gDstWindow->portRect,ditherCopy,nil);
- }
- done:
- SetGWorld(savePort,saveGD);
- } /* End of () */
-
- /********************************************
-
- Make a source window
-
- ********************************************/
-
- CWindowPtr MakeSWindow(Rect *frame,StringPtr name,GWorldPtr buffer)
-
- { CWindowPtr wind;
-
- if ( (wind = (CWindowPtr)NewCWindow(nil,frame,name,false, zoomDocProc,(WindowPtr)-1,true,0)) == nil ) {
- Error("NewCWindow Failed",0);
- return(nil);
- }
- ShowWindow((WindowPtr)wind);
- BringToFront((WindowPtr)wind); HiliteWindow((WindowPtr)wind,true);
- SetWRefCon((WindowPtr)wind,(long)buffer);
- return(wind);
- } /* End of () */
-
- /********************************************
-
- Open a file.
-
- ********************************************/
-
- OSErr DoOpen(FSSpec *fsp)
- { long result = noErr;
- Rect zpFrame;
- GWorldPtr saveWorld;
- GDHandle saveGD;
- short oFile = -1;
- StandardFileReply theSFR;
- Boolean HasCompression = true;
- long resp;
-
- if ( Gestalt(gestaltCompressionMgr, &resp) != noErr || resp < 15 )
- HasCompression = false;
-
-
- GetGWorld(&saveWorld,&saveGD);
- if ( fsp == nil ) {
- SFTypeList types = { 'PICT','JFIF',0 };
- if ( gHasNewStdFile ) {
- if (!HasCompression) StandardGetFile(nil,2,types,&theSFR);
- else StandardGetFilePreview(nil,2,types,&theSFR);
- } else {
- SFReply osfr;
- Point pt = {100,100};
-
- SFGetFile(pt,(ConstStr255Param)"",nil,1,types,nil,&osfr);
- theSFR.sfGood = osfr.good;
- theSFR.sfReplacing = osfr.copy;
- theSFR.sfType = osfr.fType;
- if ( osfr.good )
- FSMakeFSSpec(osfr.vRefNum,0L,osfr.fName,&theSFR.sfFile);
- }
- if ( !theSFR.sfGood ) {
- return(1);
- }
- } else {
- theSFR.sfFile = *fsp;
- }
-
- if ( FSpOpenDF(&theSFR.sfFile,fsRdPerm,&oFile) ) {
- result = -1;
- goto done;
- }
-
-
- /************************************************
- *
- * Get the picture frame, to see how big of a window to make.
- *
- ************************************************/
-
- if ( GetPictureFileHeader(oFile,&gOriginalPicFrame,nil ) ) {
- result = -1;
- goto done;
- }
-
- if ( gSrcWindow == nil ) {
-
- OffsetRect(&gOriginalPicFrame,-gOriginalPicFrame.left,-gOriginalPicFrame.top);
- if ( gOversample ) {
- gOriginalPicFrame.right *= 2;
- gOriginalPicFrame.bottom *= 2;
- }
- gRect = gOriginalPicFrame;
- zpFrame = gRect;
-
- if ( (result=AllocateBuffers()) != 0 )
- goto done;
- OffsetRect(&zpFrame,50,50);
- gSrcWindow = MakeSWindow(&zpFrame,theSFR.sfFile.name,gWorld);
- SetGWorld((CGrafPtr)gWorld,nil);
- if ( (result=DrawPictureFile(oFile,&gWorld->portRect,nil)) != 0 ) {
- Error("DrawPictureFile Failed",result);
- goto done;
- }
- } else {
-
- zpFrame = gRect;
- OffsetRect(&zpFrame,70,70);
- gAltWindow = MakeSWindow(&zpFrame,theSFR.sfFile.name,gAltWorld);
- SetGWorld((CGrafPtr)gAltWorld,nil);
- if ( (result=DrawPictureFile(oFile,&gAltWorld->portRect,nil)) != 0 ) {
- Error("DrawPictureFile Failed",result);
- goto done;
- }
- }
- done:
- if ( oFile != -1 )
- FSClose(oFile);
- SetGWorld(saveWorld,saveGD);
- return(result);
- } /* End of () */